package com.fu.reflect1;

import java.lang.reflect.Constructor;

/**
 * @author 付大大
 * @description
 * @create 2021-01-17 11:54
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
//        method1();

//        method2();

//        method3();
//        method4();


    }

    private static void method4() throws ClassNotFoundException, NoSuchMethodException {
        Class<?> aClass = Class.forName("com.fu.reflect1.Student");
        Constructor<?> declaredConstructor = aClass.getDeclaredConstructor(String.class);
        System.out.println(declaredConstructor);
    }

    private static void method3() throws ClassNotFoundException, NoSuchMethodException {
        Class<?> aClass = Class.forName("com.fu.reflect1.Student");
        Constructor<?> constructor = aClass.getConstructor();
        System.out.println(constructor);

        Constructor<?> constructor1 = aClass.getConstructor(String.class, int.class);
        System.out.println(constructor1);

        Constructor<?> constructor3 = aClass.getConstructor(int.class);
        System.out.println(constructor3);
    }

    private static void method2() throws ClassNotFoundException {
        Class<?> aClass = Class.forName("com.fu.reflect1.Student");
        Constructor<?>[] declaredConstructors = aClass.getDeclaredConstructors();
        for (Constructor<?> declaredConstructor : declaredConstructors) {
            System.out.println(declaredConstructor);

        }
    }

    private static void method1() throws ClassNotFoundException {
        Class<?> forName = Class.forName("com.fu.reflect1.Student");

        Constructor<?>[] constructors = forName.getConstructors();

        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor);
        }
    }
}
